class Solution {
    //解法1 首尾双指针
    public int[] exchange(int[] nums) {
        int i = 0;
        int j = nums.length-1;
        while (i < j) {
            while (i < j && (nums[i]&1) != 0) {
                i++;
            }
            while (i < j && (nums[j]&1) == 0) {
                j--;
            }
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;

        }
        return nums;
    }
    //解法2：快慢双指针
    public int[] exchange2(int[] nums) {
        int i = 0;
        int j = 0;
        while (j < nums.length) {
            if ((nums[j] & 1) !=0) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
                i++;
            }
            j++;
        }
        return nums;
    }
}